/**
 * Copyright (c) Jan 16, 2013 10:59:53 AM WKM and/or its affiliates. 
 * Use is subject to license terms.
 * All rights reserved.
 */
package org.extblog.wkm.web.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * @author WKM 属性文件
 * PropertyUtil.java history
 * 1.WKM - Jan 16, 2013 - Create File
 */
public class PropertyUtil extends PropertyPlaceholderConfigurer{

	/**属性文件**/
	private static Map<String, Object> ctxPropertiesMap;
	
	/**
	 * 
	 * (non-Javadoc)
	 * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory, java.util.Properties)
	 */
    protected void processProperties(ConfigurableListableBeanFactory beanFactory,  
            Properties props)throws BeansException {  
  
        super.processProperties(beanFactory, props);  
        //load properties to ctxPropertiesMap  
        ctxPropertiesMap = new HashMap<String, Object>();  
        for (Object key : props.keySet()) {  
            String keyStr = key.toString();  
            String value = props.getProperty(keyStr);  
            ctxPropertiesMap.put(keyStr, value);  
        }  
    }  
	
	/**
	 * 获取属性文件
	 * @param name key
	 * @return
	 */
	//static method for accessing context properties  
    public static String getValue(String key) { 
    	Object value = ctxPropertiesMap.get(key);
    	if(value instanceof String) {
    		return value.toString(); 
    	} 
    	return null;
    }
}
